<template>
	<view class="index">
		<view class="home" v-if="barCur==0">
			<home :optionVal="indexOptionVal" 
			:indexAssembly="indexAssembly"  
			@seeStore="seeStore" 
			@bCurrentChange="bCurrentChange" @cardReady="cardReady"></home>
		</view>
		<view class="store" v-if="barCur==1">
			<store :storeAssembly="storeAssembly" 
			@goodsNavChange="goodsNavChange" ref="claerGo"></store>
		</view>
		<view class="card" v-if="barCur==2">
			<card :cardAssembly="cardAssembly" @giveCard="giveCard"></card>
		</view>
		<view class="member" v-if="barCur==3">
			<member :memberAssembly="memberAssembly"></member>
		</view>
		<view class="mine" v-if="barCur==4">
			<mine :mineAssembly="mineAssembly"></mine>
		</view>
		
		<!-- 从商家扫码进入需要授权弹窗 -->
		<!-- <u-popup v-model="loginShow" mode="center" border-radius="16" width="580rpx">
			<view class="loginBox">
				<view class="popTit">微信授权登录</view>
				<view class="tips">为提供更好的服务，请先允许授权基础信息哦~</view>
				<view class="tips2">授权即同意<text>《用户协议》</text><text>《隐私政策》</text></view>
				<view class="btnBox">
					<view class="btn btn1">
						<view class="cancel" @tap="cancelLogin">取消</view>
					</view>
					<view class="btn btn2">
						<author-login @clickAgain="cancelLogin" height="60rpx" fontSize="28rpx" bgColor="#333" fontColor="#fff" title="去授权"></author-login>
					</view>
				</view>
			</view>
		</u-popup> -->
		<!-- 自定义底部导航 -->
		<u-tabbar 
		:list="barList"
		v-model="barCur"
		:mid-button="true" 
		:before-switch="beforeSwitch"
		active-color="#FF5238" 
		:border-top="false"
		icon-size="56"
		mid-button-size="104"
		inactive-color="#666" @change="barChange">
		</u-tabbar>
	</view>
</template>

<script>
	import home from '../components/index/home'
	import store from '../components/index/publicPraise'
	import card from '../components/index/liquorCard'
	import member from '../components/index/member'
	import mine from '../components/index/mine'
	export default {
		components:{
			home,
			store,
			card,
			member,
			mine
		},
		data() {
			return {
				serverUrl:'',
				url:'/api/user/moreTableList', //接口地址
				appid:"wx7d5280c4b7c4ac74", // appid
				// mini:uni.getStorageSync('mini') || null,
				shop_id:null,
				lat:0,//
				lon:0,//
				scollVal:0,
				offset : 1, //热销推荐分页页码
				// 导航
				barCur:0,
				barList:[
					{
						iconPath: "/static/tabBar/tabBar1.svg",
						selectedIconPath: "/static/tabBar/tabBarEd1.svg",
						text: '首页',
						customIcon: false,
					},
					{
						iconPath: "/static/tabBar/tabBar2.svg",
						selectedIconPath: "/static/tabBar/tabBarEd2.svg",
						text: '口碑',
						customIcon: false,
					},
					{
						iconPath: "/static/tabBar/tabBar3.svg",
						selectedIconPath: "/static/tabBar/tabBarEd3.svg",
						text: '酒卡',
						midButton: true,
						customIcon: false,
					},
					{
						iconPath: "/static/tabBar/tabBar4.svg",
						selectedIconPath: "/static/tabBar/tabBarEd4.svg",
						text: '消息',
						customIcon: false,
					},
					{
						iconPath: "/static/tabBar/tabBar5.svg",
						selectedIconPath: "/static/tabBar/tabBarEd5.svg",
						text: '我的',
						customIcon: false,
					}
				],
				// 首页值--------------------------------------------首页值
				indexOptionVal:{
					// 分享传进来的option
					scene:'',
					ref:'',
					card:'',
					// topbar
					topbar:{
						topTabType:'transparentFixed',
						topTabFontColor:'#fff'
					}
				},
				indexAssembly:{
					indexReady:null,
					// 当前城市
					curCity:'',
					choiceCity:'',//通过手动选择的城市
					// banner
					bannerList:[],
					bCurrent: 0,
					// 头条
					newsList:[],
					noticeList:[],
					// 最新活动
					newestImg:'',
					newestId:'',
					newestTime:null,
					newestType:null,
					newestInfo:null,
					// 口碑商家
					storeList:[],
					// 热销推荐
					hotList:[],
					cardReady:null
				},
				// 口碑值--------------------------------------------口碑值
				storeAssembly:{
					// 当前城市
					curCity:'',
					choiceCity:'',//通过手动选择的城市
					// banner图
					banner:null,
					// 切换
					storeName:'',
					temporary:1,
					storeList:[],
					storeReady:null,
					// 请求参数
					isLoadMore:false,
					statusPage:'',
					page: 1,
					pageSize: 10,
					waresType:1,
					// 顶部导航
					topTabType:'transparentFixed',
					topTabFontColor:'#fff',
				},
				// 酒卡值--------------------------------------------酒卡值
				cardAssembly:{
					topTabType:'transparentFixed',
					topBarBgColor:'',
					banner:null,
					// 订单列表
					cardList:[],
					cardReady:null,
					isLoadMore:false,
					page: 1,
					pageSize: 10,
					scrollTop:0,
					isGenerate:0,
					giveCard:null,
					totalCount:0,
				},
				// 会员值--------------------------------------------会员值
				memberAssembly:{
					// 信息
					memberInfo:null,
				},
				// 消息
				newsAssembly:{
					
				},
				// 我的值--------------------------------------------我的值
				mineAssembly:{
					// 信息
					memberInfo:null,
					vipInfo:null,
					topTabType:'transparentFixed',
					topTabFontColor:'#333',
				},
				// 授权登录
				loginShow:false,
			}
		},
		onShow() {
			var _this = this;
			uni.getStorage({
				key: 'currentCity',
				success: function (res) {
					_this.indexAssembly.choiceCity = res.data;
					_this.indexAssembly.curCity = _this.indexAssembly.choiceCity;
					_this.storeAssembly.choiceCity = res.data;
					_this.storeAssembly.curCity = _this.storeAssembly.choiceCity;
				}
			});
			uni.getStorage({
				key: 'ndy',
				success: function (res) {
					_this.cardAssembly.page = 1;
					_this.cardAssembly.cardReady = false;
					_this.cardAssembly.cardList = [];
					_this.getCardList();
					_this.cardAssembly.isGenerate = 0;
					uni.removeStorage({
					    key: 'ndy'
					});
				}
			});
		},
		onLoad: function (option) {
			// this.mini = uni.getStorageSync('mini') || null //用户表数据，获取owner_id
			if (!uni.getStorageSync('userInfo')) {
				//用户登录
				this.login();
			} else {
				//调用默认启动方法
				this.loadData();
			}
			
			if(option.scene){
				this.indexOptionVal.scene = option.scene;
			}
			if(option.ref){
				this.indexOptionVal.ref = option.ref;
			}
			if(option.card){
				this.indexOptionVal.card = option.card;
			}
			if(option.barCur){
				this.barCur = option.barCur;
			}
			if(this.barCur==0){//首页
				// this.isGetLocation();
				// this.getBannerList();
				// this.getheadlineList();
				// this.getNewestList();
				// this.getHotList();
				this.loadData()
			}else if(this.barCur==1){//口碑
				this.storeAssembly.storeList = [];
				this.storeAssembly.page = 1;
				this.isGetLocation();
				this.getStoreBanner();
			}else if(this.barCur==2){//酒卡
				this.cardAssembly.page = 1;
				this.cardAssembly.cardReady = false;
				this.cardAssembly.cardList = [];
				this.getCardList();
				this.getCardBanner();
				this.cardAssembly.isGenerate = 0;
			}else if(this.barCur==3){//会员
				this.getMemberInfo();
			}else if(this.barCur==4){//我的
				this.getMemberInfo();
			}else{
				this.isGetLocation();
				this.getBannerList();
				this.getheadlineList();
				this.getNewestList();
				this.getHotList();
			}
			
		},
		onPullDownRefresh() {//下拉刷新
			if(this.barCur==0){//首页
				this.indexAssembly.bCurrent = 0;
				this.indexAssembly.bannerList = [];
				this.indexAssembly.newsList = [];
				this.indexAssembly.noticeList = [];
				this.indexAssembly.newestInfo = null;
				this.indexAssembly.storeList = [];
				this.indexAssembly.hotList = [];
				this.offset=1
				this.loadData()
				
				// this.isGetLocation();
				// this.getBannerList();
				// this.getheadlineList();
				// this.getNewestList();
				// this.getHotList();
			}else if(this.barCur==1){//口碑
				this.storeAssembly.isLoadMore = false;
				this.$refs.claerGo.clear();
				this.storeAssembly.storeList = [];
				this.storeAssembly.page = 1;
				//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
				this.getStoreList();
				this.getStoreBanner();
			}else if(this.barCur==2){//酒卡
				this.cardAssembly.isLoadMore = false;
				this.cardAssembly.page = 1;
				this.cardAssembly.cardList = [];
				this.getCardList();
				this.getCardBanner();
			}else if(this.barCur==3){//会员
				this.getMemberInfo();
			}else if(this.barCur==4){//我的
				this.getMemberInfo();
			}

			setTimeout(function () {
				uni.stopPullDownRefresh();  //停止下拉刷新动画
			}, 2000);
		},
		onPageScroll(e) {
			if(this.barCur==0){//首页
				if(e.scrollTop>50){
					this.indexOptionVal.topbar.topTabType = 'fixed';
					this.indexOptionVal.topbar.topTabFontColor = '';
				}
				if(e.scrollTop < 50){
					this.indexOptionVal.topbar.topTabType = 'transparentFixed';
					this.indexOptionVal.topbar.topTabFontColor = '#fff';
				}
			}else if(this.barCur==1){
				if(e.scrollTop>50){
					this.storeAssembly.topTabType = 'fixed';
					this.storeAssembly.topTabFontColor = '';
				}
				if(e.scrollTop < 50){
					this.storeAssembly.topTabType = 'transparentFixed';
					this.storeAssembly.topTabFontColor = '#fff';
				}
			}else if(this.barCur==2){
				if(e.scrollTop>50){
					this.cardAssembly.topTabType = 'fixed';
					this.cardAssembly.topBarBgColor = '#FF5238';
				}
				if(e.scrollTop < 50){
					this.cardAssembly.topTabType = 'transparentFixed';
					this.cardAssembly.topBarBgColor = '';
				}
			}else if(this.barCur==4){
				if(e.scrollTop>50){
					this.mineAssembly.topTabType = 'fixed';
					this.mineAssembly.topTabFontColor = '';
				}
				if(e.scrollTop < 50){
					this.mineAssembly.topTabType = 'transparentFixed';
					this.mineAssembly.topTabFontColor = '#333';
				}
			}

		},
		// 滑动到底部
		onReachBottom() {
			if(this.barCur==0){//首页
				this.get_hot_topDatas(true)
			}else if(this.barCur==1){//口碑
				if(!this.storeAssembly.isLoadMore){
					if(this.storeAssembly.page!=1){
						this.getStoreList();
					}
				}
			}else if(this.barCur==2){//酒卡
				if(!this.cardAssembly.isLoadMore){
					if(this.cardAssembly.page!=1){
						this.getCardList();
					}
				}
			}
		},
		methods:{
			//---------------------------通用方法调用
			loadData() {
				this.get_indexData();//获取首页banner数据
				this.get_activtyDatas();//获取最新活动数据
				this.get_shopDatas();//获取口碑商家数据
				this.get_hot_topDatas(false);//获取热销推荐数据
				// this.get_goodsData();//单表查询
			},
			
			//----------------------------------新接口测试--获取banner数据
			async get_indexData() {
				//-------主表查询参数-------------banner参数
				let param = {};
				param.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param.dbNum = ''; //缓存编号   API默认以MD5(param)为编号
				param.table = 'advert';//主表名称
				param.listType = 2; //2查询全部  3分页查询
				param.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				param.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				param.where = {'code':'mall_home_banner','owner_id':uni.getStorageSync('shop_id')}; //主表查询条件 无需给个字符空值
				param.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				//----------请求banner
				const res = await this.$fly.post(this.url, { 
					msg: JSON.stringify(param)
				});

				//--------------------------------banner数据组装
				if (res.code == 200) {
					res.data.filter(item=>{
						if(item.pic){
							this.indexAssembly.bannerList.push({image:this.fileUrl(item.pic[0])})
						}
						
					})
					// console.log(res.data)
				} else {  
					console.log(res);
				}
			},
			
			//----------------------------------新接口测试--获取最新活动数据
			async get_activtyDatas() {
				//-------关联查询参数-------------最新活动参数
				let params = {};
				params.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params.dbNum = ''; //缓存编号   API默认以MD5(params)为编号
				params.table = 'promotion';//主表名称
				params.listType = 3; //2查询全部  3分页查询
				params.limit=1;
				params.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				params.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params.where = {}; //主表查询条件 无需给个字符空值
				params.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				let params2 = {};
				params2.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params2.dbNum = ''; //缓存编号   API默认以MD5(params2)为编号
				params2.table = 'goods';//主表名称
				params2.listType = 3; //2查询全部  3分页查询
				params2.limit=1;
				params2.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				params2.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params2.where = {'id':56}; //主表查询条件 无需给个字符空值
				params.table_list .push(params2);//多表参数数组名称 无需给个字符空或空数组
				
				const res = await this.$fly.post(this.url, {
					msg: JSON.stringify(params)
				});
			
				//--------------------------------banner数据组装
				if (res.code == 200) {
					// res.data.forEach(item=>{
					// 	this.indexAssembly.bannerList.push({image:this.fileUrl(item.pic[0])})
					// })
					if(res.data[0].goods[0].pic){
						res.data[0].image=this.fileUrl(res.data[0].goods[0].pic[0])
					}else{
						res.data[0].image=''
					}
					
					this.indexAssembly.newestInfo = res.data[0];
					console.log(res.data,'active')
				} else {
					console.log(res);
				}
			
			},
			
			//----------------------------------新接口测试--获取口碑商家数据
			async get_shopDatas() {
				let mini = uni.getStorageSync('mini')
				
				//-------主表查询参数-------------口碑商家参数
				let params = {};
				params.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params.table = 'store';//主表名称
				params.listType = 3; //2查询全部  3分页查询
				params.offset = 1; //页码(分页查询时有效) 
				params.limit = 3; //每页条数(分页查询时有效)
				params.order = 'owner_id Asc'; //表无自增ID时追加为默认排序 无需给个字符空值
				params.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params.where = {'parent_id':0,'type':1,'status':1,}; //主表查询条件 无需给个字符空值
				params.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				
				const res = await this.$fly.post(this.url, {
					msg: JSON.stringify(params)
				});
				
				// --------------------------------口碑商家数据组装
				if (res.code == 200) {
					res.data.map(item=>{
						if(item.pic){
							item.image=this.fileUrl(item.pic[0])
						}else item.image=null
					})
					this.indexAssembly.storeList=res.data
					console.log(res,"shop")
				} else {
					console.log(res,"error")
				}
			
			},
			
			//----------------------------------新接口测试--获取热销推荐数据
			async get_hot_topDatas(type) {
				let mini = uni.getStorageSync('mini')
				//-------主表查询参数-------------口碑商家参数
				let params = {};
				
				if(type){
					this.offset+=1
				}else{
					this.offset=1
				}
				params.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params.table = 'goods';//主表名称
				params.listType = 3; //2查询全部  3分页查询
				params.offset = this.offset; //页码(分页查询时有效) 
				params.limit = 4; //每页条数(分页查询时有效)
				params.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				params.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params.where = {'owner_id':uni.getStorageSync('shop_id')}; //主表查询条件 无需给个字符空值
				params.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				const res = await this.$fly.post(this.url, {
					msg: JSON.stringify(params)
				});
				
				// --------------------------------热销推荐数据组装
				if (res.code == 200) {
					res.data.map(item=>{
						if(item.pic){
							item.image=this.fileUrl(item.pic[0])
						}else{
							item.image=null
						}
					})
					if(this.offset==1){
						this.indexAssembly.hotList = res.data;
					}
					else{
						if(this.indexAssembly.hotList.length<res.sl){
							this.indexAssembly.hotList = this.indexAssembly.hotList.concat(res.data);
						}
					}
					
					
					console.log(res,"hot_top")
				} else {
					console.log(res,"error")
				}
			
			},
			
			//--优惠券(promotion_coupon)
			//--酒卡(order_team_share)
			//--个人资产(user_fund)
			//--收藏(user_follow)
			//--收益 (user_fund_log)
			async get_miniData(){
				let user_id=uni.getStorageSync('userInfo').user_id
				
				//-------主表查询参数-------------个人资产
				let params = {};
				params.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params.table = 'user_fund';//主表名称
				params.listType = 2; //2查询全部  3分页查询
				params.order = 'user_id Asc'; //表无自增ID时追加为默认排序 无需给个字符空值
				params.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params.where = {'user_id':user_id}; //主表查询条件 无需给个字符空值
				params.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				//-------主表查询参数-------------用户优惠券
				let params2 = {};
				params2.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params2.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params2.table = 'promotion_coupon';//主表名称
				params2.listType = 2; //2查询全部  3分页查询
				params2.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				params2.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params2.where = {'user_id':user_id}; //主表查询条件 无需给个字符空值
				params.table_list.push(params2);//多表参数数组名称 无需给个字符空或空数组
				
				// //-------主表查询参数-------------酒卡
				let params3 = {};
				params3.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params3.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params3.table = 'order_team_share';//主表名称
				params3.listType = 2; //2查询全部  3分页查询
				params3.order = 'order_id Asc'; //表无自增ID时追加为默认排序 无需给个字符空值
				params3.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params3.where = {'user_id':user_id}; //主表查询条件 无需给个字符空值
				params.table_list.push(params3);//多表参数数组名称 无需给个字符空或空数组
				
				//-------主表查询参数-------------收藏
				let params4 = {};
				params4.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params4.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params4.table = 'user_follow';//主表名称
				params4.listType = 2; //2查询全部  3分页查询
				params4.order = 'user_id Asc'; //表无自增ID时追加为默认排序 无需给个字符空值
				params4.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params4.where = {'user_id':user_id}; //主表查询条件 无需给个字符空值
				params.table_list.push(params4);//多表参数数组名称 无需给个字符空或空数组
				
				//-------主表查询参数-------------收益
				let params5 = {};
				params5.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params5.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params5.table = 'user_fund_log';//主表名称
				params5.listType = 2; //2查询全部  3分页查询
				params5.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				params5.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params5.where = {'user_id':user_id}; //主表查询条件 无需给个字符空值
				params.table_list.push(params5);//多表参数数组名称 无需给个字符空或空数组
				
				//----------请求个人资料
				const res = await this.$fly.post(this.url, { 
					msg: JSON.stringify(params)
				});
				
				if (res.code == 200) {
					this.mineAssembly.memberInfo = res.data[0];
					console.log(res,"mine")
				} else {
					console.log(res,"error")
				}
			},
			
			
			
			// beforeSwitch(e){
			// 	// 切换导航之前判断是否登录
			// 	let stopChange = true;
			// 	if(e==2 || e==4){
			// 		if (uni.getStorageSync('TOKEN')) {//有token
			// 			this.testToken('/site/get-info',{}).then(res => {
			// 				if(res.data.status!=200){//但token无效
			// 					this.loginShow = true;
			// 					stopChange = false;
			// 				}
			// 			})
			// 		}else{//无TOKRN
			// 			this.loginShow = true;
			// 			stopChange = false;
			// 		}
			// 	}
			// 	if(e==3){
			// 		uni.showToast({
			// 			icon: 'none',
			// 			duration:1000,
			// 			title: '开发中，尽请期待',
			// 			success: res => {
							
			// 			},
			// 		});
			// 		stopChange = false;
			// 	}
			// 	return stopChange;
			// },
			// 取消登录/或者登录后隐藏弹窗
			cancelLogin(){
				this.loginShow = false;
			},
			barChange(e){//导航切换
				if(e==3){
					this.barCur = this.barCur;
				}else{
					this.barCur = e;
				}
				if(this.barCur==0){//首页
					// if(this.indexAssembly.indexReady==null){
						// this.isGetLocation();
						// this.getBannerList();
						// this.getheadlineList();
						// this.getNewestList();
						// this.getHotList();
						this.offset=1
						this.loadData()
					// }
					this.indexOptionVal.topbar.topTabType = 'transparentFixed';
					this.indexOptionVal.topbar.topTabFontColor = '#fff';
				}else if(this.barCur==1){//口碑
					// if(this.storeAssembly.storeReady==null){
						this.storeAssembly.isLoadMore = false;
						// this.$refs.claerGo.clear();
						this.storeAssembly.storeList = [];
						this.storeAssembly.page = 1;
						this.isGetLocation();
						this.getStoreBanner();
					// }
					this.storeAssembly.topTabType = 'transparentFixed';
					this.storeAssembly.topTabFontColor = '#fff';
				}else if(this.barCur==2){//酒卡
					// if(this.cardAssembly.cardReady==null){
						this.cardAssembly.page = 1;
						this.cardAssembly.cardReady = false;
						this.cardAssembly.cardList = [];
						this.cardAssembly.isGenerate = 0;
						this.getCardList();
						this.getCardBanner();
					// }
					this.cardAssembly.topTabType = 'transparentFixed';
					this.cardAssembly.topBarBgColor = '';
				}else if(this.barCur==3){//会员
					// if(this.memberAssembly.memberInfo==null){
						this.getMemberInfo();
					// }
				}else if(this.barCur==4){//我的
					// if(this.mineAssembly.memberInfo==null){
						this.get_miniData();
					// }
					this.mineAssembly.topTabType = 'transparentFixed';
					this.mineAssembly.topTabFontColor = '#333';
				}
			},
			// 首页口碑商家模块跳转到口碑
			seeStore(e){
				this.barCur = e;
				this.storeAssembly.storeList = [];
				this.storeAssembly.page = 1;
				this.isGetLocation();
			},
			bCurrentChange(e){//banner下面的solt
				this.indexAssembly.bCurrent = e;
			},
			cardReady(e){//酒卡弹出状态
				this.indexAssembly.cardReady = e;
			},
			// 首页的数据----------------------------------------------------------------------------------------------------------------------------
			// 获取定位
			getAuthorizeInfo(a="scope.userLocation"){  //1. uniapp弹窗弹出获取授权（地理，个人微信信息等授权信息）弹窗
				var _this=this;
				uni.authorize({
					scope: a,
					success() { //1.1 允许授权
						_this.getLocationInfo();
					},
					fail(){    //1.2 拒绝授权
						console.log("你拒绝了授权，无法获得周边信息")
					}
				})
			},
			getLocationInfo(){  //2. 获取地理位置
				var _this=this;
				uni.getLocation({
					type: 'wgs84',
					success (res) {
						let latitude,longitude;
						latitude = res.latitude.toString();
						longitude = res.longitude.toString();
						_this.lat = latitude;
						_this.lon = longitude;
						uni.request({
							method:'GET',
							url:'https://apis.map.qq.com/ws/geocoder/v1/?location='+res.latitude+','+res.longitude+'&key=UNRBZ-AVCK4-QQYUP-DN6OL-2OAJO-3NFUA&get_poi=1',
							dataType:'json',
							success: (res) => {
								if(_this.indexAssembly.choiceCity==''){
									_this.indexAssembly.curCity = res.data.result.ad_info.city;
								}else{
									_this.indexAssembly.curCity = _this.indexAssembly.choiceCity;
								}
								if(_this.storeAssembly.choiceCity==''){
									_this.storeAssembly.curCity = res.data.result.ad_info.city;
								}else{
									_this.storeAssembly.curCity = _this.storeAssembly.choiceCity;
								}
							}
						});
						if(_this.barCur==0){//首页
							_this.getBusinessList();
						}else if(_this.barCur==1){
							_this.getStoreList();
						}
					}
				});
			},
			isGetLocation(a="scope.userLocation"){ // 3. 检查当前是否已经授权访问scope属性，参考下截图
				var _this=this;
				uni.getSetting({
					success(res) {					
						if (!res.authSetting[a]) {  //3.1 每次进入程序判断当前是否获得授权，如果没有就去获得授权，如果获得授权，就直接获取当前地理位置
							_this.getAuthorizeInfo()
						}else{
							_this.getLocationInfo()
						}
					}
				});
			},
			// 获取banner
			getBannerList(){
				this.apiget('/fun/advert-position/detail',{code:'mall_home_banner'}).then(res =>{
					if(res.data.status == 200 ) {
						this.indexAssembly.indexReady = 1;
						// this.indexAssembly.bannerList = res.data.data.advert;
					}
				})
			},
			// 头条
			getheadlineList(){
				var _this = this;
				this.apiget('/fun/advert-position/detail',{code:'mall_home_headline'}).then(res =>{
					if(res.data.status == 200 ) {
						_this.indexAssembly.newsList = res.data.data.advert;
						_this.indexAssembly.newsList.forEach((v,i) => {
							var newsName = v.article.title;
							_this.indexAssembly.noticeList.push(newsName);
						})
					}
				})
			},
			// 最新活动
			// getNewestList(){
			// 	var _this = this;
			// 	this.apiget('/fun/advert-position/detail',{code:'mall_home_la'}).then(res =>{
			// 		if(res.data.status == 200 ) {
			// 			if(res.data.data.advert.length>0){
			// 				var gId = res.data.data.advert[0].content;
			// 				this.apiget('/fun/goods/view',{id:gId}).then(res =>{
			// 					if(res.data.status == 200 ) {
			// 						_this.indexAssembly.newestInfo = res.data.data;
			// 					}
			// 				})
			// 				_this.indexAssembly.newestImg = res.data.data.advert[0].goods.image;
			// 				_this.indexAssembly.newestId = res.data.data.advert[0].content;
			// 				_this.indexAssembly.newestTime = res.data.data.advert[0].goods.time;	
			// 				_this.indexAssembly.newestType = res.data.data.advert[0].type;
			// 			}
			// 		}
			// 	})
			// },
			// 口碑商家
			getBusinessList(){
				this.apiget('/fun/advert-position/detail',{code:'mall_home_pp',lat:this.lat,lon:this.lon}).then(res =>{
					if(res.data.status == 200 ) {
						// this.indexAssembly.storeList = res.data.data.advert.slice(0,3);
					}
				})
			},
			// 热销推荐
			getHotList(){
				this.apiget('/fun/advert-position/detail',{code:'mall_home_hot'}).then(res =>{
					if(res.data.status == 200 ) {
						// this.indexAssembly.hotList = res.data.data.advert;
					}
				})
			},
			
			// 口碑数据--------------------------------------------------------------------------
			// 口碑中的广告位banner
			getStoreBanner(){
				this.apiget('/fun/advert-position/detail',{code:'mall_shop_banner'}).then(res =>{
					if(res.data.status == 200 ) {
						this.storeAssembly.banner = res.data.data.advert;
					}
				})
			},
			// 口碑中的商品列表
			getStoreList() {
				this.apiget('/shop/store-front/index',{page:this.storeAssembly.page,pageSize:this.storeAssembly.pageSize,sort:1,type:this.storeAssembly.waresType,lat:this.lat,lon:this.lon}).then(res =>{
					if(res.data.status == 200) {
						var newList = res.data.data.list;
						if(this.storeAssembly.waresType==1){
							newList.forEach(v=>{
								v.countdown = this.endCountDown(v.activity.end_at);
								v.timedOut = false;
							})
						}
						this.storeAssembly.storeList = this.storeAssembly.storeList.concat(newList);
						this.storeAssembly.storeReady = 1;
						if(res.data.data.list.length<this.storeAssembly.pageSize){
							this.storeAssembly.isLoadMore = true;
							this.storeAssembly.status = 'nomore';
						}else if(res.data.data.list.length==this.storeAssembly.pageSize && this.storeAssembly.page == res.data.data.pageCount){
							this.storeAssembly.isLoadMore = true;
							this.storeAssembly.status = 'nomore';
						}else{
							this.storeAssembly.status = 'loading';
							this.storeAssembly.page = ++ this.storeAssembly.page;
						}
					}
				})
			},
			// 切换
			goodsNavChange(e){
				this.storeAssembly.isLoadMore = false;
				this.storeAssembly.waresType = e;
				this.storeAssembly.storeList = [];
				this.storeAssembly.page = 1;
				this.getStoreList();
			},
			// 酒卡数据---------------------------------------------------------------------------------------------------------
			// 酒卡中的广告位banner
			getCardBanner(){
				this.apiget('/fun/advert-position/detail',{code:'mall_liquor_banner'}).then(res =>{
					if(res.data.status == 200 ) {
						this.cardAssembly.banner = res.data.data.advert;
					}
				})
			},
			getCardList(){
				this.apiget('/mall/liquor-card/index',{page:this.cardAssembly.page,pageSize:this.cardAssembly.pageSize,status:0}).then(res =>{
					if(res.data.status == 200 ) {
						this.cardAssembly.totalCount = res.data.data.totalCount;
						this.cardAssembly.cardList = this.cardAssembly.cardList.concat(res.data.data.list);
						this.cardAssembly.cardReady = 1;
						if(res.data.data.list.length<this.cardAssembly.pageSize){
							this.cardAssembly.isLoadMore = true;
							this.cardAssembly.status = 'nomore';
						}else if(res.data.data.list.length==this.cardAssembly.pageSize && this.cardAssembly.page == res.data.data.pageCount){
							this.cardAssembly.isLoadMore = true;
							this.cardAssembly.status = 'nomore';
						}else{
							this.cardAssembly.status = 'loading';
							this.cardAssembly.page = ++ this.cardAssembly.page;
						}
					}
				})
			},
			// 酒卡海报
			giveCard(val){
				this.cardAssembly.giveCard = val;
			},
			// 会员数据-------------------------------------------------------------------------
			// 我的数据
			getMemberInfo(){
				this.apiget('/fun/member/view',{}).then(res =>{
					if(res.data.status == 200 ) {
						this.mineAssembly.memberInfo = res.data.data;
						this.memberAssembly.memberInfo = res.data.data;
						var vipArr = res.data.data.vip_list;
						vipArr.forEach((v,i) => {
							if(v.is_now_level == 1){
								this.mineAssembly.vipInfo = v;
							}
						})
					}
				})
			},
			
		},
		onShareAppMessage(res) {
			var _this = this;
			return {
				title: _this.cardAssembly.giveCard.giveCardName,
				path: 'pages/index?card='+_this.cardAssembly.giveCard.giveCardVal+'&ref='+_this.cardAssembly.giveCard.invitationCode,
				imageUrl: _this.cardAssembly.giveCard.giveCardImg
			}
			_this.shareWayShow = false;
			if (res.from === 'button') { // 来自页面内分享按钮
				uni.showToast({
					title: '已发送',
					icon: 'success',
					duration: 2000,
					success: function() {}
				})
			}
		}
	}
</script>

<style lang="scss">
	.loginBox{
		padding: 0 32rpx;
		
		.popTit{
			height: 96rpx;
			padding-top: 20rpx;
			font-size: 36rpx;
			line-height: 76rpx;
			color: #333333;
			text-align: center;
			border-bottom: 2rpx solid #EFF0F3;
		}
		.tips{
			padding: 16rpx 0;
			font-size: 28rpx;
			line-height: 44rpx;
			color: #333333;
			text-align: center;
		}
		.tips2{
			padding: 16rpx 0;
			font-size: 24rpx;
			line-height: 40rpx;
			color: #999999;
			text-align: center;
			text{
				color: #7681B0;
			}
		}
		.btnBox{
			padding: 8rpx 0 24rpx;
			display: flex;
			
			.btn{
				flex: 1;
				height: 60rpx;
				font-size: 28rpx;
				text-align: center;
				line-height: 60rpx;
				border-radius: 66rpx;
				overflow: hidden;
				
				.cancel{
					width: 100%;
					height: 100%;
					color: #999;
					border: 2rpx solid #999;
					border-radius: 66rpx;
				}
			}
			.btn1{
				margin-left: 30rpx;
				margin-right: 16rpx;
			}
			.btn2{
				margin-right: 30rpx;
				margin-left: 16rpx;
			}
		}
	}
</style>
